package com.info.zhiduoduo.repository.mapper.system;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.system.AddressDto;
import com.info.zhiduoduo.repository.entity.system.Address;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2018-08-09
 */
public interface AddressMapper extends BaseMapper<Address> {

    @Select("select id,code,name,levels,levelOne as provinceCode,levelTwo as cityCode," +
            "levelThree as countyCode,levelFour as townCode " +
            "from zdd_address " +
            "where levels = 1 " +
            "and name like '${name}%'")
    List<AddressDto> getProvince(@Param("name") String name);

    @Select("select id,code,name,levels,levelOne as provinceCode,levelTwo as cityCode," +
            "levelThree as countyCode,levelFour as townCode " +
            "from zdd_address " +
            "where levels = 2 " +
            "and levelOne=#{provinceCode} " +
            "and name like '${name}%'")
    List<AddressDto> getCity(@Param("provinceCode") String provinceCode, @Param("name") String name);

    @Select("select id,code,name,levels,levelOne as provinceCode,levelTwo as cityCode," +
            "levelThree as countyCode,levelFour as townCode " +
            "from zdd_address " +
            "where levels = 3 " +
            "and levelOne=#{provinceCode} " +
            "and levelTwo=#{cityCode} " +
            "and name like '${name}%'")
    List<AddressDto> getCounty(@Param("provinceCode") String provinceCode, @Param("cityCode") String cityCode, @Param("name") String name);

    @Select(("select * from zdd_address where levels = #{level}"))
    List<AddressDto> getAddrByLevel(int level);

    @Select(("select * from zdd_address where id = #{id}"))
    Address getAddress(@Param("id") int id);
}
